package com.feri.rbacsys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feri.rbacsys.dao.BrandDao;
import com.feri.rbacsys.entity.Brand;
import com.feri.rbacsys.service.intf.BrandService;
import com.feri.rbacsys.vo.R;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * (Brand)表服务实现类
 *
 * @author makejava
 * @since 2023-03-27 21:00:18
 */
@Service
public class BrandServiceImpl extends ServiceImpl<BrandDao, Brand> implements BrandService {

    @Resource
    private BrandDao dao;
    @Override
    public R queryPage(int page, int size) {
        return R.ok(dao.selectPage(new Page<>(page,size),null));
    }

    @Override
    public R queryWhere(Brand brand) {
        //1.实例化 条件构造器对象
        QueryWrapper<Brand> queryWrapper=new QueryWrapper<>();
        //2.动态设置条件
        if(brand.getId()!=null){
            queryWrapper.like("id",brand.getId());
        }
        if(StringUtils.hasLength(brand.getName())){
            queryWrapper.like("name",brand.getName());
        }
        //排序
        queryWrapper.orderByDesc("id");
        //3.执行查询
        return new R(0,"OK",dao.selectList(queryWrapper));
    }
}

